<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地图导航</title>
    <style>

            *{
                margin:0;
                padding:0;
            }


            #container{
                width:100%;
                height:100vh;
                background-color:pink;
            }
    </style>
</head>

<body>
<div id="container"></div>
<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "1329076735fafe9ea75db11bec0733df",
    };
</script>
<script
        type="text/javascript"
        src="https://webapi.amap.com/maps?v=2.0&key=a59fbfb02b3f7eb9f4aa371576add664"
></script>
<script type="text/javascript">
    //地图初始化应该在地图容器div已经添加到DOM树之后
     var zoom = 18
     var map = new AMap.Map("container", {
       zoom: zoom,
       center:[116.397658,39.908028] ,//地图中心点坐标
     });

     //定义定位的方法
     function setLocation(lon, lat){
         map.setZoomAndCenter(zoom, [lon, lat]) //设置中心的位置

         //设置当前位置的标记
         var marker = new AMap.Marker({
             map: map,
             icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
             position: [lon, lat]
         });
         map.add(marker)

         map.plugin(['AMap.PlaceSearch'], function() {
             var PlaceSearchOptions = { //设置PlaceSearch属性
                 map:map,//在地图中显示对应的标记
                 pageSize: 4, //每页结果数,默认10
                 pageIndex: 1, //请求页码，默认1
                 extensions: "base" //返回信息详略，默认为base（基本信息）
             };
             var MSearch = new AMap.PlaceSearch(PlaceSearchOptions); //构造PlaceSearch类
             AMap.Event.addListener(MSearch, "complete",(result)=>{
                   //调用鸿蒙端的方法，现在最近的几个地址
                   //window.swift.alert(JSON.stringify(result.poiList.pois))
                   window.swift.receiveNearPlace(JSON.stringify(result.poiList.pois))
             }); //返回结果
             MSearch.searchNearBy("路边", [lon, lat]); //关键字查询
         });
     }

     window.onload=function(){
         //调用鸿蒙端的业务方法
         window.swift.setCurrentLocation()
     }
</script>
</body>
</html>